package com.idp.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.Inet4Address;

public class ApplicationUtil {

    private static final Logger log = LoggerFactory.getLogger(ApplicationUtil.class);

    public static void printStartInfo(ConfigurableApplicationContext context) {
        ConfigurableEnvironment env = context.getEnvironment();
        try {
            String ip = Inet4Address.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String path = env.getProperty("server.servlet.context-path");
            path = path != null ? "/" + path : "";

            log.info("服务启动成功\n" +
                "----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Swagger: http://{}:{}{}/doc.html" + "\n" +
                "----------------------------------------------------------",
                ip, port, path);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

}
